<template>
	<view>
		<view class="mainpadding ffffff ">
			<view class="flexbetween" @click="tzgrtx">
				<view class="ershiba xiaohei fonweight">头像</view>
				<view class="flexright">
					<view class="touxiang margin_right1">
						<image :src="avatar_text" mode=""></image>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="flexbetween margin_top" @click="tzxgnc">
				<view class="ershiba xiaohei fonweight">昵称</view>
				<view class="flexright">
					<view class="ershiba xiaohei fonweight margin_right1">{{nickname}}</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershiba xiaohei fonweight">性别</view>
				<view class="flexright">
					<u-radio-group v-model="sex" placement="row" circle>
						<u-radio activeColor="#1ba95b" :customStyle="{marginRight: '30rpx'}" label="男"
							name="0"></u-radio>
						<u-radio activeColor="#1ba95b" label="女" name="1"></u-radio>
					</u-radio-group>
				</view>
			</view>
			<view class=" margin_top flexbetween" @click="tzdz">
				<view class="ershiba xiaohei fonweight " >地址</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="flexbetween margin_top" @click="tzsjh">
				<view class="ershiba xiaohei fonweight">手机号</view>
				<view class="flexright">
					<view class="ershiba xiaohei fonweight margin_right1">{{userinfo.mobile}}</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top1"  @click="tzresfz">
			<view class="flexbetween">
				<view class="ershiba xiaohei fonweight">身份证号</view>
				<view class="flexright">
					<view class="ershiba xiaolv fonweight margin_right1">{{returnrztext(userinfo.usersmrz)}}</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit()">保存</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				avatar: "",
				avatar_text: "",
				nickname: "",
				userinfo:{},
				sex:"",
			}
		},
		onLoad() {
			this.userinfomsg()
		},
		onShow() {
			uni.$off("editname")
			uni.$on("editname",data=>{
				this.nickname = data
			})
			uni.$off("editheadimg")
			uni.$on("editheadimg",data=>{
				this.avatar = data.avatar
				this.avatar_text = data.avatar_text
			})
			uni.$off("editsmrz")
			uni.$on("editsmrz",data=>{
				this.userinfomsg()
			})
		},
		methods: {
			returnrztext(data){
				if(!data){
					return "未认证"
				}
				// 实名认证状态:1=待审核,2=认证成功,3=认证失败
				if(data.smrz_status==1){
					return "待审核"
				}else if(data.smrz_status==2){
					return "认证成功"
				}else if(data.smrz_status==3){
					return "认证失败"
				}
			},
			submit(){
				httpRequest.request('/api/user/profile', 'GET', {
					avatar:this.avatar,
					nickname:this.nickname,
					gender:this.sex
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			userinfomsg() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userinfo = res.data
					this.avatar = res.data.avatar
					this.avatar_text = res.data.avatar_text
					this.nickname = res.data.nickname
					this.sex = res.data.gender.toString()
				})
			},
			// 跳转身份证信息
			// tzsfzxx() {
			// 	uni.navigateTo({
			// 		url: '/pages_mypage/shenfenzxx'
			// 	})
			// },
			// 跳转认证身份证
			tzresfz() {
				if(!this.userinfo.usersmrz){
					uni.navigateTo({
						url: '/pages_mypage/shengfenzrz'
					})
				}else{
					uni.navigateTo({
						url: '/pages_mypage/shenhe'
					})
				}
				
			},
			// 跳转地址
			tzdz() {
				uni.navigateTo({
					url: '/pages_mypage/dizhi'
				})
			},
			// 跳转修改手机号
			tzsjh() {
				uni.navigateTo({
					url: '/pages_mypage/xiugaisjh'
				})
			},
			// 跳转修改昵称
			tzxgnc() {
				uni.navigateTo({
					url: '/pages_mypage/xiugainicheng?name='+this.nickname
				})
			},
			// 跳转个人头像
			tzgrtx() {
				let data = {
					avatar:this.avatar,
					avatar_text:this.avatar_text
				}
				uni.navigateTo({
					url: '/pages_mypage/gerentoux?data='+ encodeURIComponent(JSON.stringify(data))
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.touxiang {
		width: 132rpx;
		height: 132rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}

	page {
		background: #F9F9F9;
	}
</style>